import pinia from "../store/store";
import piniaStore from "@/store";
const store = piniaStore(pinia);
let modules = import.meta.glob("../views/**/*.vue");
let sysBaseTitle: string = "音乐后台管理系统";

// 路由列表
let routes: any = [
    {
        path: "/login",
        name: "home",
        component: () => import("@/views/login/login.vue"),
        meta: {
            title: sysBaseTitle + "-登录",
        },
    },
    {
        path: "/",
        name: "index",
        component: () => import("@/views/layout.vue"),
        meta: {
            title: sysBaseTitle,
        },
        children: [
        ],
    },
];

let menuAllListRes = [
    {
        id: 1,
        routerUrl: "/data",
        title: "数据大屏",
        icon: "#icon-shujudaping",
        path: "/data",
        name: "dashboard",
        component: "views/dashboard/index.vue",
        isHide: 2,
        parentId: 0,
        sort: 1,
    },
    {
        id: 5,
        // index: "5",
        routerUrl: "/manage",
        title: "信息管理",
        icon: "#icon-guanli",
        path: "/manage",
        name: "manage",
        component: "views/system/index.vue",
        isHide: 2,
        parentId: 0,
        sort: 1,
        children: [
            {
                id: 6,
                // index: "5-6",
                routerUrl: "/manage/user",
                title: "用户列表",
                icon: "#icon-yonghu",
                path: "user",
                name: "user",
                component: "views/system/user/user.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
            {
                id: 7,
                // index: "5-7",
                routerUrl: "/manage/role",
                title: "歌单管理",
                icon: "#icon-gedan1",
                path: "role",
                name: "role",
                component: "views/system/role/role.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
            {
                id: 8,
                routerUrl: "/manage/menu",
                title: "歌手管理",
                icon: "#icon-geshou",
                path: "menu",
                name: "menu",
                component: "views/system/menu/menu.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
            {
                id: 11,
                routerUrl: "/manage/song",
                title: "歌曲管理",
                icon: "#icon-gequ",
                path: "song",
                name: "song",
                component: "views/system/song/song.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
            {
                id: 12,
                routerUrl: "/manage/Mv",
                title: "MV管理",
                icon: "#icon-a-262_imv",
                path: "mv",
                name: "mv",
                component: "views/system/mv/mv.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
            {
                id: 15,
                routerUrl: "/manage/comment",
                title: "歌单评论管理",
                icon: "#icon-pinglun",
                path: "comment",
                name: "comment",
                component: "views/system/comment/comment.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
            {
                id: 17,
                routerUrl: "/manage/songComment",
                title: "歌曲评论管理",
                icon: "#icon-pinglun2",
                path: "songComment",
                name: "songComment",
                component: "views/system/songComment/songComment.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
            {
                id: 16,
                routerUrl: "/manage/musicInfo",
                title: "音乐资讯管理",
                icon: "#icon-zixun",
                path: "musicInfo",
                name: "musicInfo",
                component: "views/system/musicInfo/musicInfo.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
            {
                id: 13,
                routerUrl: "/manage/banner",
                title: "轮播图管理",
                icon: "#icon-carousel",
                path: "banner",
                name: "banner",
                component: "views/system/banner/banner.vue",
                isHide: 2,
                parentId: 5,
                sort: 1,
            },
        ],
    },
    // {
    //     id: 9,
    //     routerUrl: "/article",
    //     title: "文章管理",
    //     icon: "#icon-danpin",
    //     path: "/article",
    //     name: "article",
    //     component: "views/article/index.vue",
    //     isHide: 2,
    //     parentId: 0,
    //     sort: 1,
    //     children: [
    //         {
    //             id: 10,
    //             routerUrl: "/article/list",
    //             title: "文章分类",
    //             icon: "#icon-liebiaoxingshi",
    //             path: "list",
    //             name: "list",
    //             component: "views/article/list/list.vue",
    //             isHide: 2,
    //             parentId: 5,
    //             sort: 1,
    //         },
    //         {
    //             id: 11,
    //             routerUrl: "/article/classificati",
    //             title: "文章列表",
    //             icon: "#icon-xinzengdaohangliebiao",
    //             path: "classificati",
    //             name: "classificati",
    //             component: "views/article/list/classificati.vue",
    //             isHide: 2,
    //             parentId: 5,
    //             sort: 1,
    //         },
    //     ],
    // },
];

// 无限极菜单
// 根据返回的接口，重组菜单数据和路由数据
let menusRes: any = [];
let routesRes: any = [];
menuAllListRes.forEach((item) => {
    let menusResItem: any = {
        icon: item.icon,
        id: item.id,
        // index: item.index,
        routerUrl: item.routerUrl,
        title: item.title,
        isHide: item.isHide,
    };
    let routesResItem: any = {
        path: item.path,
        name: item.name,
        meta: {
            title: item.title + "-" + sysBaseTitle,
            meta:item.isHide==1? true:false, 
        },
        component: modules[`../${item.component}`],
    };
    if (item.children) {
        menusResItem.children = [];
        routesResItem.children = [];
        menuRecursiveFilter(item.children, menusResItem);
        routerRecursiveFilter(item.children, routesResItem);
    }
    //这里是为了添加页面但是不添加左侧路由而设置的
    // if(menusResItem.isHide==2){
    //     menusRes.push(menusResItem);
    // }
    menusRes.push(menusResItem);
    routesRes.push(routesResItem);
});

// 菜单数据递归
function menuRecursiveFilter(children: any, menusResItem: any) {
    children.forEach((item: any) => {
        let m: any = {
            icon: item.icon,
            id: item.id,
            index: item.index,
            routerUrl: item.routerUrl,
            title: item.title,
            isHide: item.isHide,
        };
        if (item.children) {
            m.children = [];
            menuRecursiveFilter(item.children, m);
        }
        menusResItem.children.push(m);
    });
}

// 路由数据递归
function routerRecursiveFilter(children: any, routesResItem: any) {
    children.forEach((item: any) => {
        let r: any = {
            path: item.path,
            name: item.name,
            meta: {
                title: item.title + "-" + sysBaseTitle,
            },
            component: modules[`../${item.component}`],
        };
        if (item.children) {
            r.children = [];
            routerRecursiveFilter(item.children, r);
        }
        routesResItem.children.push(r);
    });
}

routes[1].children.push(...routesRes);
store.setMenu(menusRes);
export default routes;
